//
//  RadioPlayView.m
//  PetTown
//
//  Created by lanou3g on 15/6/1.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "RadioPlayView.h"
#define LHeight self.frame.size.height
#define LWidth  self.frame.size.width
#define LJULI  (LHeight - CGRectGetMaxY(_photoImg.frame) - 130)/12
@implementation RadioPlayView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/



-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor whiteColor];
        [self setSubViews];
    }
    return self;
}
//添加视图
-(void)setSubViews{
    //中心图片
    self.photoImg = [[UIImageView alloc] initWithFrame:CGRectMake(LWidth/6, LWidth/6 - 20 , LWidth/3 * 2, LWidth/3 * 2)];
    //标题
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMinX(_photoImg.frame),CGRectGetMaxY(_photoImg.frame) + LJULI, CGRectGetWidth(_photoImg.frame), 30)];
    _titleLabel.alpha = 0.7;
    _titleLabel.textAlignment = NSTextAlignmentCenter;//设置文字居中
    //时间显示
    self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(LWidth/2 - 45, CGRectGetMaxY(_titleLabel.frame) + LJULI, 90, 20)];
    _timeLabel.font = [UIFont systemFontOfSize:14.0];
    //进度条
    self.playSlider = [[UISlider alloc] initWithFrame:CGRectMake(CGRectGetMinX(_photoImg.frame) + 20, CGRectGetMaxY(_timeLabel.frame) + LJULI, CGRectGetWidth(_photoImg.frame)-40, 20)];
    [_playSlider setThumbImage:[UIImage imageNamed:@"jindutiao.png"] forState:UIControlStateNormal];
    
    _playSlider.minimumValue = 0;
    _playSlider.maximumValue = 1;
    _playSlider.minimumTrackTintColor = [UIColor clearColor];
    _playSlider.maximumTrackTintColor = [UIColor clearColor];
    _playSlider.continuous = YES;
    //缓冲
    self.bufferView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
    _bufferView.frame = CGRectMake(CGRectGetMinX(_photoImg.frame) + 23, CGRectGetMinY(_playSlider.frame) + 10 , CGRectGetWidth(_photoImg.frame)-45, 20);
    
    //播放
    self.playButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    _playButton.frame = CGRectMake(LWidth/2 - 20, CGRectGetMaxY(_playSlider.frame) + LJULI, 40, 40);
    [_playButton setBackgroundImage:[UIImage imageNamed:@"PauseRadio.png"] forState:UIControlStateNormal];
    _playButton.imageView.alpha = 0.5;
    //上一曲
    self.lastButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    _lastButton.frame = CGRectMake(CGRectGetMinX(_photoImg.frame) - 5, CGRectGetMinY(_playButton.frame) + 5, 30, 30);
    [_lastButton setBackgroundImage:[UIImage imageNamed:@"LastRadio.png"] forState:UIControlStateNormal];
    //下一曲
    self.nextButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    _nextButton.frame = CGRectMake(CGRectGetMaxX(_photoImg.frame) - 25, CGRectGetMinY(_playButton.frame) + 5, 30, 30);
    [_nextButton setBackgroundImage:[UIImage imageNamed:@"NextRadio.png"] forState:UIControlStateNormal];
    
    [self addSubview:_photoImg];
    [self addSubview:_titleLabel];
    [self addSubview:_timeLabel];
    [self addSubview:_playButton];
    [self addSubview:_lastButton];
    [self addSubview:_nextButton];
    [self addSubview:_bufferView];
    [self addSubview:_playSlider];
}



@end
